<include file="Public/Header" />
<script src="__PUBLIC__/Manage/js/jquery.form.min.js"></script>
<table width="100%" height="31px" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
      <tr>
        <td height="31">
			<div class="titlebt">
				<if condition="I('get.do')=='add'">
					添加会员
				<else />
					修改会员信息
                </if>
			</div>
		</td>
      </tr>
    </table>

<div class="main">

	<div class="form">
		<php>$do = I('get.do');</php>
		<form method='post' id="form_do" name="form_do" action="{:U('Member/Lists', 'do='.$do)}">
        <if condition="I('get.do')=='add'">
            <dl>
                <dt><span style="color:red;">*</span> 用户名：</dt>
                <dd>
                    <input type="text" name="name" class="inp_one" placeholder="用户名只能由4-20位英文、数字或者下划线组成" id="name" maxlength="20" />
                </dd>
            </dl>

            <dl>
                <dt><span style="color:red;">*</span> 密码：</dt>
                <dd>
                    <input type="password" name="pass" class="inp_one" id="pass" placeholder="长度限制6-20" maxlength="20" />
                </dd>
            </dl>

            <dl>
                <dt> 支付密码：</dt>
                <dd>
                    <input type="password" name="paypass" class="inp_one" id="paypass" placeholder="长度限制6-20" maxlength="20" />
                </dd>
            </dl>

            <dl>
                <dt> 绑定手机：</dt>
                <dd>
                    <input type="text" name="phone" class="inp_one" id="phone" />
                </dd>
            </dl>

            <dl>
                <dt> 绑定邮箱：</dt>
                <dd>
                    <input type="text" name="email" class="inp_one" id="email" />
                </dd>
            </dl>
            <script>
                $(document).ready(function() {
                    $.validator.addMethod("username", function(value, element) {
                        var v = $.trim(value);
                        var l = v.length;
                        if(l === 0) return false;
                        if( l < 4 || l > 20 ) return false;
                        var preg = /^[a-zA-Z_\d]{4,20}$/;
                        if( ! preg.exec(value) ) return false;
                        var preg = /^\d{11}$/;
                        if( preg.exec(value) ) return false;
                        return true;
                    }, "请正确输入用户名");

                    $("#form_do").validate({
                       rules: {
                           name: {
                               required: true,
                               username: true,
                               remote:{
                                   type: 'POST',
                                   url: "{:U('Api/chkUsernameIsExists')}",
                                   data: {
                                       user_name: function() {
                                           return $("#name").val();
                                       }
                                   }
                               }
                           },
                           pass: {
                               required: true,
                               rangelength: [6, 20]
                           },
                           paypass: {
                               required: false,
                               rangelength: [6, 20]
                           },
                           phone: {
                               required: false,
                               rangelength: [11, 11],
                               digits: true,
                               remote:{
                                   type: 'POST',
                                   url: "{:U('Api/chkUsernameIsExists')}",
                                   data: {
                                       user_name: function() {
                                           return $("#email").val();
                                       }
                                   }
                               }
                           },email: {
                               required: false,
                               email: true,
                               remote:{
                                   type: 'POST',
                                   url: "{:U('Api/chkUsernameIsExists')}",
                                   data: {
                                       user_name: function() {
                                           return $("#email").val();
                                       }
                                   }
                               }
                           }
                       },
                       messages: {
                           name: {
                               required: "请输入用户名",
                               username: "用户名只能由4-20位英文、数字或者下划线组成",
                               remote: "用户名已经被占用"
                           },
                           pass: {
                               required: "请输入密码",
                               rangelength: "密码长度限制6-20"
                           },
                           paypass: {
                               rangelength: "支付密码长度限制6-20"
                           },
                           phone: {
                               rangelength: "手机号码长度不正确",
                               digits: "请输入一个正确的手机",
                               remote: "该手机号码已被占用"
                           },
                           email: {
                               email: "请输入一个正确的邮箱",
                               remote: "该邮箱已被占用"
                           }
                       }
                   })
                });
            </script>
        <else />
            <dl>
                <dt> 用户名：</dt>
                <dd>
                    <input type="text" name="name" class="inp_one" value="{$mark.user_name}" id="name" maxlength="20" readonly />
                </dd>
            </dl>

            <dl>
                <dt> 密码：</dt>
                <dd>
                    <input type="password" name="pass" class="inp_one" placeholder="长度限制6-20(不修改密码则不填)" id="pass" maxlength="20" />
                </dd>
            </dl>

            <dl>
                <dt> 支付密码：</dt>
                <dd>
                    <input type="password" name="paypass" class="inp_one" placeholder="长度限制6-20(不修改密码则不填)" id="paypass" maxlength="20" />
                </dd>
            </dl>

            <dl>
                <dt> 绑定手机：</dt>
                <dd>
                    <input type="text" name="phone" class="inp_one" value="{$mark.user_phone}" id="phone" />
                </dd>
            </dl>

            <dl>
                <dt> 绑定邮箱：</dt>
                <dd>
                    <input type="text" name="email" class="inp_one" value="{$mark.user_email}" id="email" />
                </dd>
            </dl>

            <input type="hidden" value="{$mark.user_id}" name="id" id="uid">
            <script type="text/javascript">
                $(document).ready(function() {
                    $("#form_do").validate({
                        rules: {
                            pass: {
                                required: false,
                                rangelength: [6, 20]
                            },
                            paypass: {
                                required: false,
                                rangelength: [6, 20]
                            },
                            phone: {
                                required: false,
                                rangelength: [11, 11],
                                digits: true,
                                remote:{
                                    type: 'POST',
                                    url: "{:U('Api/chkUsernameIsExists')}",
                                    data: {
                                        user_name: function() {
                                            return $("#phone").val();
                                        },
                                        user_id: function(){
                                            return $("#uid").val();
                                        }
                                    }
                                }
                            },
                            email: {
                                required: false,
                                email: true,
                                remote:{
                                    type: 'POST',
                                    url: "{:U('Api/chkUsernameIsExists')}",
                                    data: {
                                        user_name: function() {
                                            return $("#email").val();
                                        },
                                        user_id: function(){
                                            return $("#uid").val();
                                        }
                                    }
                                }
                            }
                        },
                        messages: {
                            pass: {
                                required: "请输入密码",
                                rangelength: "密码长度限制6-20"
                            },
                            paypass: {
                                rangelength: "支付密码长度限制6-20"
                            },
                            phone: {
                                rangelength: "手机号码长度不正确",
                                digits: "请输入一个正确的手机",
                                remote: "该手机号码已被占用"
                            },
                            email: {
                                email: "请输入一个正确的邮箱",
                                remote: "该邮箱已被占用"
                            }
                        }
                    })
                });
            </script>
        </if>
		<div class="form_b">
			<input type="submit" class="btn_blue" value="提 交"> <input type="reset" class="btn_blue" value="重置"/>
		</div>
	   </form>
	</div>
</div>
<include file="Public/Copyright" />
</body>
</html>
